package com.csc.mtlbatch.jde.cls;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Ct087 {

	private static final Logger LOGGER = LoggerFactory.getLogger(Ct087.class);
	
	public boolean writing(){
		
		boolean ret = false;
	
		String[] springConfig  = 
			{	
				"com/csc/mtlbatch/springbatch/jobs/bt087Job.xml" 
			};
		
		ApplicationContext context = 
				new ClassPathXmlApplicationContext(springConfig);
		
		JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
		Job job = (Job) context.getBean("bt087Job");

		try {

			JobParameters jobParameters = 
					  new JobParametersBuilder()
					  .addLong("time",System.currentTimeMillis()).toJobParameters();
			
			JobExecution execution = jobLauncher.run(job, jobParameters);		
			LOGGER.info("Exit Status : " + execution.getStatus());
			ret = true;
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return ret;
	
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Boolean retGen = false;
		
		Ct087 write = new Ct087();
		retGen = write.writing();
		if (retGen){
			LOGGER.info("File generate Success.");
		}else{
			LOGGER.info("File generate Fail.");
		}		
		System.exit(0);
	}

}
